package com.atguigu.paymentdemo.utils;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

@Data
@Accessors(chain = true) // 开启链式变成最终所有的返回值都是R了
public class R {

    private Integer code;

    private String message;

    private Map<String, Object> data = new HashMap<>();

    public static R ok() {
        R r = new R();
        r.setCode(0);
        r.setMessage("success");
        return r;
    }

    public static R error() {
        R r = new R();
        r.setCode(-1);
        r.setMessage("false");
        return r;
    }

    // 链式编程
    public R put(String key, Object val){
        this.data.put(key, val);
        return this;
    }

}

